package com.activit.test;

import org.activiti.engine.*;
import org.activiti.engine.repository.Deployment;
import org.activiti.engine.repository.DeploymentBuilder;
import org.junit.Test;

import java.util.HashMap;
import java.util.Map;

/**
 * @ClassName AcivitiDemoByBPMN
 * @Description TODO
 * @Author director吴
 * @Date 2022/4/26 18:03
 * @Version 1.0
 **/
public class AcivitiDemoByBPMN {


    //测试部署
    @Test
    public void testDeeploment() {

        //1.获取配置类processEngineConfiguration
        ProcessEngineConfiguration processEngineConfiguration = ProcessEngineConfiguration
                .createProcessEngineConfigurationFromResource("activiti.cfg.xml", "processEngineConfiguration");

        //2.获取配置类processEngine工作流引擎
        ProcessEngine processEngine = processEngineConfiguration.buildProcessEngine();

        //3.获取配资源部署类的相关service -[ Repository ]
        RepositoryService repositoryService = processEngine.getRepositoryService();

        //4.创建流程部署
        DeploymentBuilder builder = repositoryService.createDeployment();
        builder.name("出差申请流程-uel");
        builder.addClasspathResource("bpmn/newEvection.bpmn20.xml");

        Deployment deployment = builder.deploy();

        System.out.println("流程部署id=" + deployment.getId());

        System.out.println("流程部署name=" + deployment.getName());

    }

    /*
        测试uel表达式
     */
    @Test
    public void test1(){

        ProcessEngine defaultProcessEngine = ProcessEngines.getDefaultProcessEngine();
        RuntimeService runtimeService = defaultProcessEngine.getRuntimeService();

        Map<String,Object> assigneeMap = new HashMap<>();

        assigneeMap.put("account1", "小李");
        assigneeMap.put("account2", "张经理");
        assigneeMap.put("account3", "赵总经理");
        assigneeMap.put("account4", "财务审批");

       runtimeService.startProcessInstanceByKey("newEvection",assigneeMap );
    }


}
